package com.study.forumsystemproject.model;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.study.forumsystemproject.common.Result;
import com.study.forumsystemproject.common.ResultCode;
import com.study.forumsystemproject.exception.ApplicationException;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
@Data
@Schema(name = "用户类", description = "描述论坛系统中的用户信息")
@Slf4j
public class User {
    private Long id;
    @Schema(description = "用户名",  example = "user123")
    @NotBlank(message = "用户名不能为空")
    private String username;
    @Schema(description = "密码")
    private String password;
    @Schema(description = "确认密码", example = "password")
    private String verifyPassword;
    @NotBlank(message = "昵称不能为空")
    @Schema(description = "昵称", example = "昵称123")
    private String nickname;
    @Schema(description = "手机号码", example = "13800138000")
    private String phoneNum;

    @Schema(description = "邮箱地址", example = "user@example.com")
    private String email;

    @Schema(description = "性别", allowableValues = {"0", "1", "2"}, example = "1")
    // 假设0表示未知，1表示男性，2表示女性
    private Integer gender;


    @Schema(description = "加密盐值", hidden = true)
    private String salt;

    @Schema(description = "头像URL", example = "http://example.com/avatar.jpg")
    @JsonInclude(JsonInclude.Include.ALWAYS) // 不论任何情况都参与JSON序列化
    private String avatarUrl;
    @Schema(description = "发表文章数量", example = "10")
    private Integer articleCount;

    @Schema(description = "是否是管理员", allowableValues = {"0", "1"}, example = "0")
    // 假设0表示不是管理员，1表示是管理员
    private Integer isAdmin;

    @Schema(description = "备注信息", example = "这是一个备注")
    private String remark;

    @Schema(description = "用户状态", allowableValues = {"0", "1"}, example = "0")

    // 假设0表示正常，1表示禁用
    private Integer state;
    @Schema(description = "删除标志", allowableValues = {"0", "1"}, example = "0")
    // 假设0表示未删除，1表示已删除
    private Integer deleteFlag;

    @Schema(description = "创建时间", example = "2024-01-01T12:00:00Z")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @Schema(description = "更新时间", example = "2024-01-02T12:00:00Z")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    public static void isBean(Integer state) {
        if(state != 0) {
            log.warn(ResultCode.FAILED_USER_BANNED.toString());
            throw new ApplicationException(Result.fail(ResultCode.FAILED_USER_BANNED));
        }
    }

}